package com.activityes.primeirapagina;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.main.primeirapagina.R;

/**
 * 
 * @author Hydrus Technology.
 *
 */
public class CardapioActivity extends ListActivity implements
		OnItemClickListener {

	private List<Map<String, Object>> viagens;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String[] de = { "icone", "categoria", "descricao" };
		int[] para = { R.id.icone_categoria, R.id.categoria, R.id.descricao };
		SimpleAdapter adapter = new SimpleAdapter(this, listarViagens(),
				R.layout.activity_cardapio, de, para);
		setListAdapter(adapter);
		getListView().setOnItemClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_dashboard, menu);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_cardapio:
			startActivity(new Intent(this, CardapioActivity.class));
			return true;
		case R.id.menu_pedidos:
			startActivity(new Intent(this, ResumoPedidoActivity.class));
			return true;
		case R.id.menu_historico:
			return false;
		case R.id.menu_top:
			return false;
		default:
			return super.onMenuItemSelected(featureId, item);
		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Map<String, Object> map = viagens.get(position);
		String destino = (String) map.get("categoria");
		String mensagem = "Opção selecionada: " + destino;
		Toast.makeText(this, mensagem, Toast.LENGTH_SHORT).show();
		if (destino.equalsIgnoreCase("Comidas")) {
			startActivity(new Intent(this, ComidasActivity.class));
		}
	}

	private List<Map<String, Object>> listarViagens() {
		viagens = new ArrayList<Map<String, Object>>();
		Map<String, Object> item = new HashMap<String, Object>();
		item.put("icone", R.drawable.comidas);
		item.put("categoria", "Comidas");
		// item.put( "categoria", R.style.TitleFont );
		item.put("descricao", "(Cebola, Carne)");
		viagens.add(item);
		item = new HashMap<String, Object>();
		item.put("icone", R.drawable.bebidas);
		item.put("categoria", "Bebidas");
		item.put("descricao", "(Whisky,Cerveja)");
		viagens.add(item);
		item = new HashMap<String, Object>();
		item.put("icone", R.drawable.sobremesas);
		item.put("categoria", "Sobremesas");
		item.put("descricao", "(Doces, Tortas)");
		viagens.add(item);
		item = new HashMap<String, Object>();
		item.put("icone", R.drawable.sobremesas);
		item.put("categoria", "Entradas");
		item.put("descricao", "(Queijo, Pães)");
		viagens.add(item);
		return viagens;
	}

}
